from plotly.subplots import make_subplots
import plotly.graph_objs as go
import numpy as np
import time
from  PIL  import Image
# im = Image.open("/Users/user/PycharmProjects/text1/A36514B1-1757-400E-BEA5-3DA468283B3E_1_105_c.jpeg")
# print(im)
start = time.time()
N = 100
y0 = (100 * np.random.randn(N) + 6).astype(int)
y1 = (400 * np.random.randn(N) + 8).astype(int)
y2 = (100 * np.random.randn(N) + 3).astype(int)
y3 = (200 * np.random.randn(N) + 7).astype(int)
y4 = (100 * np.random.randn(N) + 9).astype(int)
y5 = (100 * np.random.randn(N) + 8).astype(int)
y6 = (100 * np.random.randn(N) + 8).astype(int)
y7 = (100 * np.random.randn(N) + 9).astype(int)
y8 = (100 * np.random.randn(N) + 32).astype(int)
y9 = (100* np.random.randn(N) + 66).astype(int)
y10 = (300 * np.random.randn(N) + 7).astype(int)
y11 = (100 * np.random.randn(N) + 9).astype(int)
y12 = (500 * np.random.randn(N) + 36).astype(int)
y13 = (100 * np.random.randn(N) + 6).astype(int)
y14 = (100 * np.random.randn(N) + 2).astype(int)
y15 = (300 * np.random.randn(N) + 9).astype(int)
y16 = (600 * np.random.randn(N) + 6).astype(int)
y17 = (300 * np.random.randn(N) + 9).astype(int)

y_data = [y0, y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15,y16,y17]
x_data = ['Bay1', 'Bay2', 'Bay3']
name_data = ['STOM', 'IT-FF', 'IT-4E']
line_name = ['X6','Shasta']
list1 = []
list2 =[]
colors = ['#fcefe8', '#789262', '#e3f9fd','#f3f9f1','#c2ccd0','pink']  # modify to have three colors
for i in name_data:
    for c in x_data:
        p = f'{c}<br>\t<br>{i}'
        print(p)
        list1.append(p)
for num in line_name:
    for i in range(len(list1)):
        name = f'{list1[i]}<br>\t<br>{num}'
        list2.append(name)
print(list2)
fig = go.Figure()
for i in range(6):  # loop over groups of three plots
    start = i * 3
    end = start + 3
    for y, n, col in zip(y_data[start:end], list2[start:end], [colors[i]] * 3):
        fig.add_trace(go.Box(y=y,boxpoints='all', jitter=0.6, pointpos=0,
                             name=n, whiskerwidth=0.4, #fillcolor= 'red',marker_color = 'yellow',
                             marker_size=3,line_width=1,opacity = 0.8)) #marker_coloe = col ,marker_size= 散点的大小，marker_color = 散点的颜色
# fig.update_traces(marker = dict(size = 2.5))
fig.update_layout(
    title={'text': 'It_FF_Leak_Rata', 'x': 0.5}, #标题设置在中间
    legend_title_text='  设备标识',
    xaxis={"rangeslider": {"bgcolor": "#e9f1f6"}}, #滑块颜色设置
    xaxis_title='Lable/Bay',
    yaxis={'title': 'Data'},
    paper_bgcolor='rgb(243, 243, 243)', # 背景颜色设置
    # plot_bgcolor='rgb(243, 243, 243)',
    template = 'ggplot2',  #ggplot2,gridon,plotly_dark,seaborn,xgridoff #设置不同的模版背景
    # images = [{'source':im, "sizex": 1.5,
    #         "sizey": 1.5,
    #         "yanchor": "bottom",
    #         "opacity": 0.5,  设置图片背景
# }],
    # showlegend = False
    # border = dict(borderradius = 10),
    # xaxis=dict(
        # rangeslider=dict(
            # visible=True,
            # thickness=0.05,
            # bordercolor='gray',
            # borderwidth=1,
            # bgcolor='white',
            # 设置圆角样式
            # bordercorners='round'
        # ))

        # marker =''  可以设置散点的形状，大小，颜色
    # zerolinecolor='rgb(255, 255, 255)',
)

fig.show()
print(fr'程序共计运行时间为{round(time.time() - start,2)}秒')